package com.hogan.basiclibrary.base.fragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.hogan.basiclibrary.R;
import com.hogan.basiclibrary.base.app.BaseApplication;
import com.hogan.basiclibrary.base.utils.SharedPreferencesUtils;


/**
 * Created by chenhu on 2017/10/31.
 */

public class BaseFragment extends Fragment {
    protected BaseApplication mBaseApplication;
    protected SharedPreferencesUtils mSharedPreferencesUtils;
    protected Context mContext;
    protected FragmentManager fragmentManager;

    public BaseFragment() {

    }

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mContext = getActivity();
        mBaseApplication = (BaseApplication) BaseApplication.getInstance();
        mSharedPreferencesUtils = SharedPreferencesUtils.getInstance(mContext);
        fragmentManager = getChildFragmentManager();
    }

    protected void shortToast(String message) {
        Toast.makeText(mContext, message, Toast.LENGTH_SHORT).show();
    }

    protected void longToast(String message) {
        Toast.makeText(mContext, message, Toast.LENGTH_LONG).show();
    }

    protected void shortSnack(String message) {
        if (null == getRootView()) {
            return;
        }
        Snackbar snackbar = Snackbar.make(getRootView(), message, Snackbar.LENGTH_SHORT);
        snackbar.getView().setBackgroundColor(ContextCompat.getColor(mContext, R.color.abc_tint_switch_thumb));
        snackbar.show();
    }

    public View getRootView() {
        return ((ViewGroup) getActivity().findViewById(android.R.id.content)).getChildAt(0);
    }

}
